package com.sso.config;

import com.sso.auth.MyAuthenticationHandler;
import org.apereo.cas.authentication.AuthenticationEventExecutionPlan;
import org.apereo.cas.authentication.AuthenticationEventExecutionPlanConfigurer;
import org.apereo.cas.authentication.principal.DefaultPrincipalFactory;
import org.apereo.cas.configuration.CasConfigurationProperties;
import org.apereo.cas.services.ServicesManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 类 {@code MyAuthenticationEventExecutionPlanConfiguration} 自定义CAS注册配置 <br> 自定义CAS注册配置.
 *
 * <p>详细描述
 * <p>
 *
 * @author <a href="mailto:lz2392504@gmail.com">CN華少</a>
 * @see CasConfigurationProperties
 * @see AuthenticationEventExecutionPlanConfigurer
 * @since v1.0.0
 */
@Configuration("MyAuthenticationEventExecutionPlanConfiguration")
@EnableConfigurationProperties(CasConfigurationProperties.class)
public class MyAuthenticationEventExecutionPlanConfiguration implements AuthenticationEventExecutionPlanConfigurer {

    @Autowired
    @Qualifier(value = "servicesManager")
    private ServicesManager servicesManager;

    @Override
    public void configureAuthenticationExecutionPlan(final AuthenticationEventExecutionPlan plan) {
        var myAuthenticationHandler = new MyAuthenticationHandler(MyAuthenticationHandler.class.getName(), servicesManager, new DefaultPrincipalFactory(), 1);
        plan.registerAuthenticationHandler(myAuthenticationHandler);
    }

    @Override
    public String getName() {
        return AuthenticationEventExecutionPlanConfigurer.super.getName();
    }

    @Override
    public int getOrder() {
        return AuthenticationEventExecutionPlanConfigurer.super.getOrder();
    }
}
